#ifndef XMPP_CLIENT_CONNECTION_H
#define XMPP_CLIENT_CONNECTION_H

#include <QSslSocket>
#include <xmpp_configuration.h>
#include "zfpear_global.h"



class XmppStreamParser;
class XmppElement;
class Message;
class Roster;

//class ZFPEARSHARED_EXPORT XmppClientConnection:public QObject {
class  XmppClientConnection:public QObject {
    Q_OBJECT
public:
    XmppClientConnection();
    ~XmppClientConnection();
    bool auto_presence() {return autoPresence_;};
    void set_auto_presence(bool autoPresence) {autoPresence_=autoPresence;};
    bool auto_roster(){return autoRoster_;};
    void set_auto_roster(bool autoRoster) {autoRoster_=autoRoster;};

    void Send(XmppElement* xmppElement);
    void ConnectToServer(const QString& host, const QString& user, const QString& passwd,
                         const QString& domain, int port=5222);

signals:
    void OnSaslStart();
    void HostFound();
    void Connected();
    void OnIq();

private slots:
    void SocketHostFound();
    void SocketReadReady();
    void SocketEncrypted();
    void SocketConnected();
    void SocketDisconnected();
    void SocketError(QAbstractSocket::SocketError);
    void SocketSslErrors(const QList<QSslError> &);

    void OnStreamStart(XmppElement* xmppElement);
    void OnStreamEnd(XmppElement* xmppElement);
    void OnStreamElement(XmppElement* xmppElement);

private:
    void SendBindIQ();
    void SendStartStream();
    void SendAuthPlain();
    void SendToServer(const QByteArray& data);
    void SendStartTls();
    void SendSessionIQ();
    void SendAutoRoster();
    void SendAutoPresence();
    void ProcessPresence(Presence* presence);
    void ProcessMessage(Message* message);
    void ProcessRosterIq(Roster* roster);
    QSslSocket socket_;

    XmppStreamParser *xmppStreamParser_;
    XmppConfiguration xmppConfiguration_;
    bool sessionAvaliable_;
    QString bind_id_;
    QString session_id_;
    bool autoRoster_;
    bool autoPresence_;



};
class  RosterListener {
public:
        ~RosterListener() {}
        virtual void rosterReceived(Roster& roster) = 0;
};
#endif // XMPP_CLIENT_CONNECTION_H
